package com.example.okhttpdemo.adapter;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.example.okhttpdemo.R;
import com.example.okhttpdemo.po.ArticleCat;

import java.util.List;

public class ArticleCatAdapter extends RecyclerView.Adapter<ArticleCatAdapter.ViewHolder> {
   class ViewHolder extends  RecyclerView.ViewHolder{
       TextView catId;
       TextView catName;
       public ViewHolder(View view){
           super(view);
           catId=view.findViewById(R.id.cat_id);
           catName=view.findViewById(R.id.cat_name);
       }
   }
    private List<ArticleCat> cats;
    public ArticleCatAdapter(List<ArticleCat> articleCats){
        cats=articleCats;

    }


    @NonNull
    @Override
    public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {

        View itemView=LayoutInflater.from(parent.getContext()).inflate(R.layout.fruit_item,parent,false);
        ViewHolder viewHolder=new ViewHolder(itemView);

        return viewHolder;
    }

    @Override
    public void onBindViewHolder(@NonNull ViewHolder holder, int position) {
        ArticleCat cat=cats.get(position);
        holder.catId.setText(cat.getId());
        holder.catName.setText(cat.getCat_name());
    }

    @Override
    public int getItemCount() {
        return cats.size();
    }
}
